﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PagedList.cs" company="XamlNinja">
//   2011 Richard Griffin and Ollie Riches
// </copyright>
// <summary>
//   Generic collection defining paging information as well as the actual collection items
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace WP7Contrib.Collections
{
    using System.Collections;
    using System.Collections.Generic;

    /// <summary>
    /// Generic collection defining paging information as well as the actual collection items.
    /// </summary>
    /// <typeparam name="T">The type being used for binding.
    /// </typeparam>
    public sealed class PagedList<T> : IPagedList<T> where T : class, new()
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PagedList{T}"/> class.
        /// </summary>
        public PagedList() : this(0)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="PagedList{T}"/> class.
        /// </summary>
        /// <param name="pageSize">
        /// The page size.
        /// </param>
        public PagedList(int pageSize)
        {
            this.Total = 0;
            this.PageIndex = 0;
            this.PageSize = pageSize;
            this.Items = new List<T>();
        }

        #region IPagedList<T> Members

        /// <summary>
        /// Gets or sets the total collection size.
        /// </summary>
        public int Total { get; set; }

        /// <summary>
        /// Gets or sets the page index.
        /// </summary>
        public int PageIndex { get; set; }

        /// <summary>
        /// Gets or sets the page size.
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// Gets or sets the items collection.
        /// </summary>
        public List<T> Items { get; set; }

        /// <summary>
        /// Returns an enumerator that iterates through the collection.
        /// </summary>
        /// <returns>
        /// Returns an enumerator for the collection.
        /// </returns>
        public IEnumerator<T> GetEnumerator()
        {
            return this.Items.GetEnumerator();
        }

        /// <summary>
        /// Returns an enumerator that iterates through the collection.
        /// </summary>
        /// <returns>
        /// Returns an enumerator for the collection.
        /// </returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }

        #endregion
    }
}